/*****************************************************************************
State of Aadhaar Survey 2017-2018

Title: 0_genvar_roster_pub.do
Author: IDinsight
Contact: stateofaadhaar@idinsight.org
Date: 29 August 2018
Data: "SOA2018_roster_cleaned.dta" -- cleaned, roster survey data
Description: 	This .do file generates variables to be used in the analysis
				of the 2018 State of Aadhaar survey data, for the roster
				component of the survey (i.e. questions on all members of the
				respondent's household).
				It saves output to "SOA2018_roster_cleaned_gen.dta"
				as well as "SOA2018_roster_cleaned_gen.csv".

Contents:

	0. Creating categories of household member characteristics used in regressions
	(The following sections generate variables for analysis for each section of 
	the 2018 State of Aadhaar report.)
	1. Enrolment
	2. Data quality
	3. General usage
	4. Banking
	5. Mobile
	6. PDS
	7. User awareness
	8. NREGA
	
Missing data code:
	.r = refused
	.d = don't know
*****************************************************************************/

	
* Setting up
	
	version 14
	capture log close
	clear all
	mac drop _all
	set more off
	
	* Please replace "..." below with the correct file path on your computer
	if "`c(os)'"=="MacOSX"{
		global dir "/Users/`c(username)'/.../SOA2018_data_release/"
		}
	else{
		global dir "C:/Users/`c(username)'/.../SOA2018_data_release/"
		}

	cd "${dir}/Data_sets/"
	use "SOA2018_roster_cleaned.dta", clear
	

/*****************************************************************************
0. Creating categories of household member characteristics used in regressions
*****************************************************************************/

	* To generate: sc_cat st_cat rel_muslim female_member member_noschool member_above60

	* Caste (of household and household member)

		gen gen_cat = (category == 1) if !missing(category)
		gen sc_cat = (category == 2) if !missing(category)
		gen st_cat = (category == 3) if !missing(category)
		gen obc_cat = (category == 4) if !missing(category)
		
		label variable gen_cat "General category"
		label variable sc_cat "SC category"
		label variable st_cat "ST category"
		label variable obc_cat "OBC Category"
		
	* Religion (of household and household member)

		gen rel_muslim = (religion == 2) if !missing(religion)
		label variable rel_muslim "Muslim household member"

	* Gender (of household member)
	
		gen female_member = (gender == 2) if !missing(gender)
		label variable female_member "Female household member"
	
	
	* Education: adult household member has no schooling
	
		gen member_noschool = (education <= 2) if age >= 18 & !missing(education) 
		* 1 = not literate
		* 2 = no schooling but literate
		label variable member_noschool "(Adult) household member has not attended school"	
		
	* Age: household member above age 60
	
		gen member_above60 = (age > 60) if age >= 18 & !missing(age)
		label variable member_above60 "(Adult) household member above age 60"


/*****************************************************************************
1. Enrolment
*****************************************************************************/

	* No roster variable generated in this section
	

/*****************************************************************************
2. Data quality
*****************************************************************************/

	* Generating categories for how much was paid to get an Aadhaar
		gen payscale =.
		replace payscale = 1 if aadhaar_paymentetrs < 50
		replace payscale = 2 if aadhaar_paymentetrs >= 50 & aadhaar_paymentetrs <= 200
		replace payscale = 3 if aadhaar_paymentetrs > 200 & !missing(aadhaar_paymentetrs)
		replace payscale =.d if aadhaar_paymentetrs == .d
		
		label define payscale 1 "Less than 50" 2 "50 to 200" 3 "Above 200"
		label values payscale payscale
		
	* Generating a dummy indicating someone paid more than 25 Rs to get an Aadhaar
		gen aadhaar_payment_25 = (aadhaar_paymentetrs > 25) if !missing(aadhaar_paymentetrs)

		
/*****************************************************************************
3. General usage
*****************************************************************************/	

	* No roster variable generated in this section

/*****************************************************************************
4. Banking
*****************************************************************************/	

	* No roster variable generated in this section	
		
/*****************************************************************************
5. Mobile
*****************************************************************************/			

	* No roster variable generated in this section

/*****************************************************************************
6. PDS
*****************************************************************************/		
	
	* No roster variable generated in this section

/*****************************************************************************
7. User awareness
*****************************************************************************/		
	
	* No roster variable generated in this section

/*****************************************************************************
8. NREGA
*****************************************************************************/	

	* No roster variable generated in this section

	
*** Saving

	save "SOA2018_roster_cleaned_gen.dta", replace
	outsheet using "SOA2018_roster_cleaned_gen.csv", comma replace
